package com.shinewind.pojo.result;

import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(description = "Result类，用于对返回结果进行统一封装")
public class Result implements Serializable {
    @ApiModelProperty(value = "返回的数据")
    private Object data;
    @ApiModelProperty(value = "执行是否成功")
    private boolean flag;
    @ApiModelProperty(value = "返回的消息")
    private String message;

    @ApiOperation(value="执行成功")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "data",value = "返回的数据",dataType = "Object"),
            @ApiImplicitParam(name = "flag",value = "执行是否成功",dataType = "boolean")
    })
    public static Result success(Object data,boolean flag){
        Result result = Result.builder()
                .data(data)
                .flag(flag)
                .build();
        return result;
    }

    @ApiOperation(value="执行成功")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "data",value = "返回的数据",dataType = "Object"),
            @ApiImplicitParam(name = "flag",value = "执行是否成功",dataType = "boolean"),
            @ApiImplicitParam(name = "message",value = "返回的消息")
    })
    public static Result success(Object data,boolean flag,String message){
        Result result = Result.builder()
                .data(data)
                .flag(flag)
                .message(message)
                .build();
        return result;
    }

    @ApiOperation(value="执行成功")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "flag",value = "执行是否成功",dataType = "boolean"),
            @ApiImplicitParam(name = "message",value = "返回的消息")
    })
    public static Result success(boolean flag,String message){
        Result result = Result.builder()
                .flag(flag)
                .message(message)
                .build();
        return result;
    }

    @ApiOperation(value="执行失败")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "flag",value = "执行是否成功",dataType = "boolean"),
            @ApiImplicitParam(name = "message",value = "返回的消息")
    })
    public static Result fail(boolean flag,String message){
        Result result = Result.builder()
                .flag(flag)
                .message(message)
                .build();
        return result;
    }

    @ApiOperation(value="执行失败")
    public static Result fail(@ApiParam(value = "返回的消息") String message){
        Result result = Result.builder()
                .message(message)
                .build();
        return result;
    }
}
